﻿using System;
using System.Collections.Generic;
using System.Text;
using BCMS.Business.DataContract;
using System.ComponentModel;
using BCMS.Settings;

namespace BCMS.FrontEnd.DataContract
{
    public class CouponUI : INotifyPropertyChanged
    {
        public string Serial { get; set; }
        public string CodeBase { get; set; }
        public long CodeNumber { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime ExpireDate { get; set; }
        public decimal ParValue { get; set; }
        public string Status { get; set; }
        public string Note { get; set; }
        public string ReleaseKind { set; get; }
        public string ReleaseTarget { set; get; }
        public string ReleaseDetail { set; get; }
        public string ReleaseName { set; get; }
        public string ReleaseNote { set; get; }
        public string ClaimBy { get; set; }
        public DateTime? ClaimDate { set; get; }
        public DateTime LastUpdated { set; get; }

        public CouponUI() { }

        public CouponUI(CouponInfo item, ReleaseInfo rls)
        {
            this.Serial = item.Serial;
            this.CodeBase = item.Serial.Split('-')[0];
            this.CodeNumber = Convert.ToInt64(item.Serial.Split('-')[1]);
            this.StartDate = item.StartDate;
            this.ExpireDate = item.ExpireDate;
            this.ParValue = item.ParValue;
            this.ReleaseName = rls.Name;
            this.ReleaseNote = rls.Note;
            this.ClaimDate = item.ClaimDate;
            switch (item.Status)
            {
                case (int)CStatus.Normal:
                    this.Status = Params.NORMAL;
                    break;
                case (int)CStatus.Claimed:
                    this.Status = Params.CLAIMED;
                    break;
                case (int)CStatus.Expired:
                    this.Status = Params.EXPIRED;
                    break;
                case (int)CStatus.Disposed:
                    this.Status = Params.DISPOSED;
                    break;
            }
            switch (rls.Target)
            {
                case (int)RTarget.CUSTOMER:
                    this.ReleaseTarget = "Khách hàng";
                    break;
                case (int)RTarget.PARTNER:
                    this.ReleaseTarget = "Đối tác";
                    break;
                case (int)RTarget.STAFF:
                    this.ReleaseTarget = "Nhân viên";
                    break;
                case (int)RTarget.OTHER:
                    this.ReleaseTarget = "Khác";
                    break;
                default:
                    this.ReleaseTarget = "ERROR";
                    break;
            }
            switch (rls.Kind)
            {
                case (int)RKind.SELL:
                    this.ReleaseKind = "Bán";
                    break;
                case (int)RKind.DISCOUNT:
                    this.ReleaseKind = "Chiết khấu";
                    break;
                case (int)RKind.GIFT:
                    this.ReleaseKind = "Quà tặng";
                    break;
                case (int)RKind.OTHER:
                    this.ReleaseKind = "Khác";
                    break;
                default:
                    this.ReleaseKind = "ERROR";
                    break;
            }

            this.ReleaseDetail = rls.Detail;
            this.Note = item.Note;
            this.LastUpdated = item.LastUpdated;
        }


        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        #endregion
    }

    public enum CStatus
    {
        Normal = 1,
        Claimed = 2,
        Expired = 3,
        Disposed = 4    
    }
}
